//
//  LCShowComposeViewNoImagesCell.swift
//  JKBiblicalReading
//
//  Created by admin on 2018/8/20.
//  Copyright © 2018年 LC. All rights reserved.
//

import UIKit

class LCSugarListTableCell: LCSendSugarListBaseTableCell {
        var model: LCSugarListModel? {
            didSet{
                imageUrl = model?.user.avatar//作者头像
                contentLabel.text = model?.note
                usernameButton.setTitle(model?.user.username
                    ?? "", for: .normal)
                var location = model?.user.location ?? ""
                let uptime = model?.uptime ?? ""
                location = location.trimmingCharacters(in: .whitespaces)
                addtimeButton.setTitle("\(location)  \(uptime)", for: .normal)
                let credit = model?.credit ?? ""
                pingLunButton.setTitle(" 赠送:  \(credit) 福音值", for: .normal)
            }
        }
        
        var imageUrl: String? {
            didSet{
                authorImageView.image = UIImage(named: "作者简介_默认")
                if imageUrl == nil || imageUrl == "" {
                }else{
                    let urlstr = URL(string: imageUrl!)
                    authorImageView.sd_setImage(with: urlstr, completed: nil)
                }
            }
        }
        //
        //    //FIXME:-告知删除对应的图片
        //    var closeEvent:(()->())?
        
        //FIXME:- 上午10:29 设置视图
        ///设置视图
    override func setupUI(){
            //        backgroundColor = randomColor()//UIColor(white: 235 / 255, alpha: 1)
            contentView.addSubview(authorImageView)
            authorImageView.snp.makeConstraints { (make) in
                make.left.top.equalTo(contentView).offset(15)
                make.width.height.equalTo(55)
            }
            contentView.addSubview(usernameButton)
            usernameButton.snp.makeConstraints { (make) in
                make.top.equalTo(self.authorImageView.snp.top)
                make.left.equalTo(self.authorImageView.snp.right).offset(15)
                make.height.equalTo(30)
                make.right.equalTo(contentView.snp.right).offset(0)
            }
//            addtimeButton.backgroundColor = randomColor()
            contentView.addSubview(addtimeButton)
            addtimeButton.snp.makeConstraints { (make) in
                make.top.equalTo(self.usernameButton.snp.bottom)
                make.left.equalTo(self.usernameButton.snp.left).offset(0)
                make.right.equalTo(contentView.snp.right).offset(0)
                make.height.equalTo(addtimeButton.snp.height)
            }
            
            contentView.addSubview(contentLabel)
            contentLabel.snp.makeConstraints { (make) in
                make.top.equalTo(addtimeButton.snp.bottom).offset(15)
                make.left.equalTo(usernameButton.snp.left).offset(0)
                make.right.equalTo(contentView.snp.right).offset(-15)
                make.height.equalTo(contentLabel.snp.height)
            }
            contentView.addSubview(pingLunButton)
            pingLunButton.snp.makeConstraints { (make) in
                make.top.equalTo(contentLabel.snp.bottom).offset(15)
                make.left.equalTo(usernameButton.snp.left).offset(0)
            }
            
            let margin: CGFloat = 20
            
            self.setupAutoHeight(withBottomView: pingLunButton, bottomMargin: margin)
            
        }
        @objc fileprivate func pingLunButtonClick(){
            print("评论")
            
        }
    
//        override func layoutSubviews() {
//            super.layoutSubviews()
//            addtimeButton.sizeToFit()
//        }
        //
        //FIXME:- 懒加载控件
        lazy var authorImageView:UIImageView = {
            let authorImageView : UIImageView = UIImageView()
            authorImageView.layer.masksToBounds = true
            // 设置圆角大小
            authorImageView.layer.cornerRadius = 55.0/2
            authorImageView.contentMode = .scaleAspectFill;
            authorImageView.clipsToBounds = true;
            
            return authorImageView
        }()
        
        lazy var contentLabel : UILabel = {
            let label: UILabel = UILabel()
            label.textColor = UIColor.darkGray
            label.numberOfLines = 0
            label.font = UIFont.systemFont(ofSize: 18)
            label.textAlignment = .left
            label.backgroundColor = UIColor.clear
            return label
        }()
        
        lazy var usernameButton: UIButton = {
            let button = UIButton()
            LCUtils.didChangeButtonLeft(forAlignment: button)
            button.titleLabel?.font = UIFont.systemFont(ofSize: 22)
            button.setTitleColor(UIColor.black, for: .normal)
            button.setTitle("用户昵称", for:.normal)
            return button
        }()
        
        lazy var addtimeButton: UIButton = {
            let button = UIButton()
            LCUtils.didChangeButtonLeft(forAlignment: button)
            button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
//            button.addTarget(self, action: #selector(addtimeButtonClick), for: .touchUpInside)
            button.setTitle("发布时间", for:.normal)
            button.setTitleColor(UIColor.lightGray, for: .normal)
//            button.titleLabel?.numberOfLines = 2

            return button
        }()
        lazy var pingLunButton: UIButton = {
            let button = UIButton()
            button.titleLabel?.font = UIFont.systemFont(ofSize: 16)
            button.addTarget(self, action: #selector(pingLunButtonClick), for: .touchUpInside)
            //留言
            button.setImage(UIImage(named: "i_icon_fyz"), for: .normal)
            //button.setTitle("", for:.normal)
            button.setTitleColor(UIColor.lightGray, for: .normal)
            return button
        }()
    
}

